package net.sky.oa.service.ioffice.impl;

import java.util.Date;
import java.util.List;
import java.text.ParseException;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.htsoft.core.service.impl.BaseServiceImpl;
import com.htsoft.core.web.paging.PagingBean;

import net.sky.oa.dao.ioffice.OffTaskDao;
import net.sky.oa.model.OffTask;
import net.sky.oa.service.ioffice.OffTaskService;


@Service
@Transactional
public class OffTaskServiceImpl extends BaseServiceImpl<OffTask> implements OffTaskService {
	
	private OffTaskDao offTaskDao;
	
	@Resource
	public void setOffTaskDao(OffTaskDao offTaskDao) {
		super.setDao(offTaskDao);
		this.offTaskDao = offTaskDao;
	}



	public OffTask findById(Long id, Long rusrId, String sort, PagingBean pb) {
		return offTaskDao.findById(id, rusrId, sort, pb);
	}

	public List<OffTask> findByRusr(Long rusrId, HttpServletRequest request, PagingBean pb) {
		int type=-1;
		Date beginTime=null;
		Date endTime=null;
		String title=request.getParameter("Q_title_S_LK");
		String rank=request.getParameter("Q_rank_N_EQ");
		String bTime=request.getParameter("Q_begintime_D_GE");
		String eTime=request.getParameter("Q_endtime_D_LE");
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		
		if(StringUtils.isNotEmpty(rank))type=Integer.valueOf(rank);
		try {
			if(StringUtils.isNotEmpty(bTime))beginTime=sf.parse(bTime);
			if(StringUtils.isNotEmpty(eTime))endTime=sf.parse(eTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return offTaskDao.findByRusr(rusrId, type, title, beginTime, endTime, pb);
	}
	
	
	
}
